package com.darren.archive.dao.impl;

import com.darren.archive.dao.SysParameterDao;
import com.darren.archive.entity.SysParameter;
import com.darren.framework.dao.impl.GenericDaoImpl;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class SysParameterDaoImpl extends GenericDaoImpl<SysParameter, Long> implements SysParameterDao {

	@Override
	public List<SysParameter> getAll() {
		Session session = sessionFactory.getCurrentSession();
		Query<SysParameter> query  = session.createQuery(" from SysParameter ",SysParameter.class);
		return query.list();
	}
	
	@Override
	public SysParameter getSystemParameter(String lookupCat, String lookupType){
		Session session = sessionFactory.getCurrentSession();	
		Query<SysParameter> query  = session.createQuery(" from SysParameter where lookupCat =:lookupCat and lookupType = :lookupType ",SysParameter.class);
		query.setParameter("lookupCat", lookupCat);
		query.setParameter("lookupType", lookupType);
		List<SysParameter> sysParameters = query.list();
		if(sysParameters != null && sysParameters.size() > 0){
			return sysParameters.get(0);
		}
		return null;
	}
	
}